/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package BeanManager;

import java.util.List;

import mapper.MessageMapper;
import org.apache.ibatis.session.SqlSession;
import packageEntities.Messages;

import service.ConnexionBd;
import static service.ConnexionBd.session;

/**
 *
 * @author nmeli
 */
public class MessageManager {
     public static List< Messages> affiche() {
      SqlSession unesession= ConnexionBd.getConnexion();
MessageMapper message = session.getMapper(MessageMapper.class);           
            List<Messages> mesMessages = message.getAll();
                 ConnexionBd.closeConnexion();
    return mesMessages;
}
      public static boolean ajout(Messages mess) {
        int nbMod = 0;
        SqlSession session = ConnexionBd.getConnexion();
        MessageMapper message = session.getMapper(MessageMapper.class);
        nbMod = message.AjoutMessage(mess);

        session.commit();

        ConnexionBd.closeConnexion();
        return (nbMod > 0 ? true : false);
   
      }
       public static  List<Messages> afficheParMembre(int id) {
      SqlSession unesession= ConnexionBd.getConnexion();
            MessageMapper message = session.getMapper(MessageMapper.class);           
            List<Messages> mesMessages = message.selectByMsgTo(id);
            ConnexionBd.closeConnexion();
            return mesMessages;
}
}